from django.db import models


class Category(models.Model):
    name = models.CharField(max_length=100, null=False)
    create_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return '<Category(id=%s, name=%s)>' % (self.id, self.name)

    class Meta:
        db_table = 'category'


class Article(models.Model):
    title = models.CharField(max_length=100, null=False)
    content = models.TextField(null=False)
    create_time = models.DateTimeField(auto_now_add=True)
    category = models.ForeignKey('Category', on_delete=models.CASCADE, null=True, related_query_name='articles')

    def __str__(self):
        return '<Article(id=%s, title=%s, content=%s)>' % (self.id, self.title, self.content)

    class Meta:
        db_table = 'article'
